package com.vhans.api.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.vhans.core.web.controller.BaseController;
import com.vhans.core.web.model.Result;
import com.vhans.core.web.page.TableDataInfo;
import com.vhans.db.model.dto.ConditionDTO;
import com.vhans.db.model.dto.bandwidthgroups.BandwidthGroupsDTO;
import com.vhans.db.model.vo.bandwidthgroups.BandwidthGroupsInfoVO;
import com.vhans.db.model.vo.bandwidthgroups.BandwidthGroupsVO;
import com.vhans.db.service.IBandwidthGroupsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 带宽和安全组Controller控制器post
 * 
 * @author vhans
 * @date 2023-05-20
 */
@Api(tags = "带宽和安全组模块")
@RestController
@RequestMapping("/dome/groups")
public class BandwidthGroupsController extends BaseController {
    @Autowired
    private IBandwidthGroupsService bandwidthGroupsService;

    /**
     * 查询带宽和安全组列表
     * @param condition 条件
     * @return {@link BandwidthGroupsVO} 题目列表
     */
    @ApiOperation(value = "查询带宽和安全组列表")
    @SaCheckPermission("dome:groups:list")
    @GetMapping("/list")
    public TableDataInfo list(ConditionDTO condition) {
        startPage();
        List<BandwidthGroupsVO> list = bandwidthGroupsService.selectBandwidthGroupsVOList(condition);
        return getDataTable(list);
    }

    /**
     * 获取带宽和安全组详细信息
     * @param id 带宽和安全组id
     * @return {@link Result<BandwidthGroupsInfoVO>} 带宽和安全组信息
     */
    @ApiOperation(value = "获取带宽和安全组编辑信息")
    @SaCheckPermission("dome:groups:query")
    @GetMapping(value = "/info/{id}")
    public Result<BandwidthGroupsInfoVO> getInfo(@PathVariable("id") Integer id) {
        return Result.success(bandwidthGroupsService.selectBandwidthGroupsInfoById(id));
    }

    /**
     * 新增带宽和安全组
     *
     * @param bandwidthGroups 带宽和安全组信息
     * @return {@link Result<>}
     */
    @ApiOperation(value = "新增带宽和安全组")
    @SaCheckPermission("dome:groups:add")
    @PostMapping("/add")
    public Result<Integer> add(@Validated @RequestBody BandwidthGroupsDTO bandwidthGroups) {
        Integer id = bandwidthGroupsService.insertBandwidthGroups(bandwidthGroups);
        return Result.success(id);
    }

    /**
     * 修改带宽和安全组
     */
    @ApiOperation(value = "修改带宽和安全组")
    @SaCheckPermission("dome:groups:update")
    @PutMapping("/update")
    public Result<?> update(@Validated @RequestBody BandwidthGroupsDTO bandwidthGroups) {
        bandwidthGroupsService.updateBandwidthGroups(bandwidthGroups);
        return Result.success();
    }

    /**
     * 删除带宽和安全组
     *
     * @param idList 需要删除的带宽和安全组主键列表
     * @return {@link Result<>}
     */
    @ApiOperation(value = "删除带宽和安全组")
    @SaCheckPermission("dome:groups:delete")
	@DeleteMapping("/delete")
    public Result<?> delete(@RequestBody List<Integer> idList) {
        return toAjax(bandwidthGroupsService.deleteBandwidthGroupsByIdIdList(idList));
    }
}
